﻿@model IEnumerable<_65_Deleting_multiple_rows_in_mvc.Models.Employee>

 <script src="~/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
 <script type="text/javascript" language="javascript">

     $(function () {
         $("#checkAll").click(function () {
             $("input[name='employeeIdsToDelete']").attr("checked", this.checked);
         });

         $("input[name='employeeIdsToDelete']").click(function () {

             if ($("input[name='employeeIdsToDelete']").length == $("input[name='employeeIdsToDelete']:checked").length) {
                 $("#checkAll").attr("checked", "checked");
             }
             else {
                 $("#checkAll").removeAttr("checked");
             }
         });

         $("#btnSubmit").click(function () {
             var cnt = $("input[name='employeeIdsToDelete']:checked").length;
             if (cnt == 0) {
                 alert("No row selected");
                 return false;
             }
             else {
                return confirm(cnt + " row(s) will be deleted");
             }

         });

     });
 
 </script>

<div style="font-family:Arial">
<h2>Employee List</h2>

@using (Html.BeginForm("Delete", "Home", FormMethod.Post))
{
<table border="1">
    <thead>
        <tr>
            <th>
                <input type="checkbox"  id="checkAll" />
            </th>
            <th>
                Name
            </th>
            <th>
                Gender
            </th>
            <th>
                Email
            </th>
        </tr>
    </thead>
    <tbody>
        @Html.EditorForModel()
    </tbody>
</table>
    <br />
<input type="submit" value="Delete selected employees" id="btnSubmit" />
}
</div>
